import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/TbBaseCheckPlan/tbBaseCheckPlan/list',
  save= '/TbBaseCheckPlan/tbBaseCheckPlan/add',
  edit= '/TbBaseCheckPlan/tbBaseCheckPlan/editBpmStatus',
  deleteOne = '/TbBaseCheckPlan/tbBaseCheckPlan/delete',
  deleteBatch = '/TbBaseCheckPlan/tbBaseCheckPlan/deleteBatch',
  importExcel = '/TbBaseCheckPlan/tbBaseCheckPlan/importExcel',
  exportXls = '/TbBaseCheckPlan/tbBaseCheckPlan/exportXls',
  tbBaseCheckRecordList = '/TbBaseCheckPlan/tbBaseCheckPlan/listTbBaseCheckRecordByMainId',
  tbBaseCheckRecordSave= '/TbBaseCheckPlan/tbBaseCheckPlan/addTbBaseCheckRecord',
  tbBaseCheckRecordEdit= '/TbBaseCheckPlan/tbBaseCheckPlan/editTbBaseCheckRecord',
  tbBaseCheckRecordDelete = '/TbBaseCheckPlan/tbBaseCheckPlan/deleteTbBaseCheckRecord',
  tbBaseCheckRecordDeleteBatch = '/TbBaseCheckPlan/tbBaseCheckPlan/deleteBatchTbBaseCheckRecord',
  tbBaseCheckPlanApprovalRecordList = '/TbBaseCheckPlan/tbBaseCheckPlan/listTbBaseCheckPlanApprovalRecordByMainId',
  tbBaseCheckPlanApprovalRecordSave= '/TbBaseCheckPlan/tbBaseCheckPlan/addTbBaseCheckPlanApprovalRecord',
  tbBaseCheckPlanApprovalRecordEdit= '/TbBaseCheckPlan/tbBaseCheckPlan/editTbBaseCheckPlanApprovalRecord',
  tbBaseCheckPlanApprovalRecordDelete = '/TbBaseCheckPlan/tbBaseCheckPlan/deleteTbBaseCheckPlanApprovalRecord',
  tbBaseCheckPlanApprovalRecordDeleteBatch = '/TbBaseCheckPlan/tbBaseCheckPlan/deleteBatchTbBaseCheckPlanApprovalRecord',
  editBpmStatus = '/TbBaseCheckPlan/tbBaseCheckPlan/editBpmStatus',
  editStatus= '/TbBaseCheckPlan/tbBaseCheckPlan/editStatus',
  editAlterApprover = '/TbBaseCheckPlan/tbBaseCheckPlan/editAlterApprover'
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

export const editBpmStatusApprove = (params,handleSuccess) => {
  return defHttp.post({ url: Api.editBpmStatus, params }).then(() => {
    handleSuccess();
  });
}

export const editAlterApprover = (params,handleSuccess) => {
  return defHttp.post({ url: Api.editAlterApprover, params }).then(() => {
    handleSuccess();
  });
}

/**
 * 计划完成确认
 */
export const editStatusComplete = (params) => {
  return defHttp.post({ url: Api.editStatus, params });
}
  
/**
 * 列表接口
 * @param params
 */
export const tbBaseCheckRecordList = (params) => {
  if(params['planId']){
    return defHttp.get({ url: Api.tbBaseCheckRecordList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const tbBaseCheckRecordDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.tbBaseCheckRecordDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const tbBaseCheckRecordDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.tbBaseCheckRecordDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  tbBaseCheckRecordSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.tbBaseCheckRecordEdit : Api.tbBaseCheckRecordSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const tbBaseCheckRecordImportUrl = '/TbBaseCheckPlan/tbBaseCheckPlan/importTbBaseCheckRecord'

/**
 * 导出
 */
export const tbBaseCheckRecordExportXlsUrl = '/TbBaseCheckPlan/tbBaseCheckPlan/exportTbBaseCheckRecord'
  
/**
 * 列表接口
 * @param params
 */
export const tbBaseCheckPlanApprovalRecordList = (params) => {
  if(params['planId']){
    return defHttp.get({ url: Api.tbBaseCheckPlanApprovalRecordList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const tbBaseCheckPlanApprovalRecordDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.tbBaseCheckPlanApprovalRecordDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const tbBaseCheckPlanApprovalRecordDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.tbBaseCheckPlanApprovalRecordDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  tbBaseCheckPlanApprovalRecordSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.tbBaseCheckPlanApprovalRecordEdit : Api.tbBaseCheckPlanApprovalRecordSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const tbBaseCheckPlanApprovalRecordImportUrl = '/TbBaseCheckPlan/tbBaseCheckPlan/importTbBaseCheckPlanApprovalRecord'

/**
 * 导出
 */
export const tbBaseCheckPlanApprovalRecordExportXlsUrl = '/TbBaseCheckPlan/tbBaseCheckPlan/exportTbBaseCheckPlanApprovalRecord'
